package com.xzm.project.ui.activity;

import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.Button;

import com.xzm.project.R;

/**
 * author : xuzongmeng
 * date   : 2019/2/19.
 * desc   : 手把手教你使用 补间动画 (视图动画)  https://blog.csdn.net/carson_ho/article/details/72827747
 */
public class TweenAnimActivity extends BaseActivity {
    private Button btnTranslate;
    private Button btnScale;
    private Button btnRotate;
    private Button btnAlpha;

    @Override
    protected int getLayoutID() {
        return R.layout.activity_tween;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        btnTranslate = findViewById(R.id.btnTranslate);
        btnScale = findViewById(R.id.btnScale);
        btnRotate = findViewById(R.id.btnRotate);
        btnAlpha = findViewById(R.id.btnAlpha);

    }

    @Override
    protected void initListener() {
        btnTranslate.setOnClickListener(v -> {
            executeTranslate();
        });
        btnScale.setOnClickListener(v -> {
            executeScale();
        });
        btnRotate.setOnClickListener(v -> {

        });
        btnAlpha.setOnClickListener(v -> {

        });
    }

    private void executeTranslate() {
//        Animation translateAnimation = AnimationUtils.loadAnimation(this, R.anim.view_animation_translate);
//        btnTranslate.startAnimation(translateAnimation );

        TranslateAnimation translateAnimation = new TranslateAnimation(0, 500, 0, 500);
        translateAnimation.setDuration(3000);
        btnTranslate.startAnimation(translateAnimation);
        // 步骤2：创建平移动画的对象：平移动画对应的Animation子类为TranslateAnimation
        //        // 参数分别是：
        //        // 1. fromXDelta ：视图在水平方向x 移动的起始值
        //        // 2. toXDelta ：视图在水平方向x 移动的结束值
        //        // 3. fromYDelta ：视图在竖直方向y 移动的起始值
        //        // 4. toYDelta：视图在竖直方向y 移动的结束值
    }

    private void executeScale() {
        Animation animation = AnimationUtils.loadAnimation(this, R.anim.view_animation_scale);
        btnScale.startAnimation(animation);
    }

    private void executeRotate() {
        Animation animation = AnimationUtils.loadAnimation(this, R.anim.view_animation_rotate);
        btnRotate.startAnimation(animation);
    }

    private void executeAlpha() {
        Animation animation = AnimationUtils.loadAnimation(this, R.anim.view_animation_alpha);
        btnAlpha.startAnimation(animation);
    }

}
